package com.yjyw.tiexie.common.permission;

import android.app.Activity;
import android.os.Build;

import java.util.List;

/**
 * Created by SmallYou on 2018/12/3 0003.
 * DESC:TODO()
 */

public abstract class PermissionHelper {
    private Activity activity;

    public PermissionHelper(Activity activity) {
        this.activity = activity;
    }

    public Activity getHost() {
        return activity;
    }

    public static PermissionHelper newInstance(Activity activity) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return new OldApiHelper(activity);
        } else {
            return new NewApiHelper(activity);
        }
    }

    public abstract void requestPermissions(int requestCode, String... perms);

    /**
     * 检查拒绝权限是否有点击不再询问
     * 如果有一个拒绝询问则返回true
     *
     * @param denied
     * @return
     */
    public boolean somePermissionNotAskAgain(List<String> denied) {
        for (String item : denied) {
            if (!shouldShowRequestPermissionRationale(item)) {
                return true;
            }
        }
        return false;
    }

    //注：如果用户在过去拒绝了权限请求，并在权限请求系统对话框中选择了 Don’t ask again 选项，此方法将返回 false。如果设备规范禁止应用具有该权限，此方法也会返回 false。
    protected abstract boolean shouldShowRequestPermissionRationale(String item);


}
